package org.itboys.rpc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.dto.MemberDetail;
import org.itboys.dto.base.Result;
import org.itboys.member.entity.Member;
import org.itboys.rpc.service.BaseRpcService;
import org.itboys.rpc.service.member.RpcMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 *会员相关（买家）
 * @author weisky
 */
@Controller
@RequestMapping(value = "/rpc/member")
public class RpcMemberController extends BaseRpcService {

    @Autowired
    private RpcMemberService rpcMemberService;

    /**
     * 登录
     * @param mobile
     * @param password
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/login")
    public Result<MemberDetail> memberLogin(String mobile, String password,
            HttpServletRequest request,HttpServletResponse response){
        return rpcMemberService.login(mobile, password);
    }

    /**
     * 快速注册
     * @param member:
     *        	username:手机号
     *          password:密码
     * @param validateCode:验证码
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/regist")
    public Result<MemberDetail> regist(Member member, String validateCode,
            HttpServletRequest request,HttpServletResponse response){
        return rpcMemberService.regist(member, validateCode);
    }
    
    /**
     * 修改用户信息
     * @param memberDetail
     * @param logos
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateInfo")
    public Result<MemberDetail> updateInfo(MemberDetail memberDetail, MultipartFile logos,
    		HttpServletRequest request,HttpServletResponse response){
    	return rpcMemberService.updateInfo(memberDetail, logos);
    }
    
    /**
     * 忘记密码（找回密码）
     * @param mobile
     * @param validateCode
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findPasswd")
    public Result<Void> findPasswd(String mobile,String validateCode,
    		HttpServletRequest request,HttpServletResponse response){
    	return rpcMemberService.findPasswd(mobile, validateCode);
    }
    
    /**
     * 修改密码
     * @param mobile
     * @param oldPwd
     * @param newPwd
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updatePasswd")
    public Result<Void> updatePasswd(String mobile,String oldPwd,String newPwd,
    		HttpServletRequest request,HttpServletResponse response){
    	return rpcMemberService.updatePasswd(mobile, oldPwd, newPwd);
    }
}
